

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>ExponentialSmoothing Module &mdash; Nyoka 4.2.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript">
          var DOCUMENTATION_OPTIONS = {
              URL_ROOT:'../',
              VERSION:'4.2.0',
              LANGUAGE:'None',
              COLLAPSE_INDEX:false,
              FILE_SUFFIX:'.html',
              HAS_SOURCE:  true,
              SOURCELINK_SUFFIX: '.txt'
          };
      </script>
        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> Nyoka
          

          
          </a>

          
            
            
              <div class="version">
                4.2
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <ul>
                <li class="toctree-l1"><a class="reference internal" href="../statsmodels_to_pmml.html">Statsmodels Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../keras_model_to_pmml.html">Keras Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../retinanet.html">RetinaNet Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../lgb_to_pmml.html">LightGBM Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../pre_process.html">Pre-Processing Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../skl_to_pmml.html">Scikit-Learn Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../xgboost_to_pmml.html">XGBoost Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../exponential_smoothing.html">ExponentialSmoothing Exporter Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../preprocess_nyoka.html">Nyoka's Pre-Processing Module</a></li>
                <li class="toctree-l1"><a class="reference internal" href="../enums.html">Enums Module</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Nyoka</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="index.html">Module code</a> &raquo;</li>
        
      <li>ExponentialSmoothing</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for ExponentialSmoothing</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">absolute_import</span>

<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">os</span>
<span class="n">BASE_DIR</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="vm">__file__</span><span class="p">))</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">BASE_DIR</span><span class="p">)</span>


<span class="kn">from</span> <span class="nn">PMML44</span> <span class="k">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span>
<span class="kn">import</span> <span class="nn">metadata</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">enums</span> <span class="k">import</span> <span class="o">*</span>

<div class="viewcode-block" id="ExponentialSmoothingToPMML"><span class="k">class</span> <span class="nc">ExponentialSmoothingToPMML</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Write a PMML file using model-object, model-parameters and time series data. Models are built using Statsmodels.</span>

<span class="sd">    Parameters:</span>
<span class="sd">    -----------</span>
<span class="sd">    results_obj: </span>
<span class="sd">        Instance of HoltWintersResults from statsmodels</span>
<span class="sd">    pmml_file_name: string</span>
<span class="sd">        Name of the PMML</span>
<span class="sd">    model_name : string (optional)</span>
<span class="sd">        Name of the model</span>
<span class="sd">    description : string (optional)</span>
<span class="sd">        Description of the model</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">results_obj</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pmml_file_name</span><span class="o">=</span><span class="s2">&quot;from_ExponentialSmoothing.pmml&quot;</span><span class="p">,</span> <span class="n">model_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>

        <span class="k">def</span> <span class="nf">get_time_value_objs</span><span class="p">():</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Does not have time attribute</span>

<span class="sd">            Parameters:</span>
<span class="sd">            -----------</span>
<span class="sd">            ts_data: pandas Series</span>

<span class="sd">            Returns:</span>
<span class="sd">            --------</span>
<span class="sd">            time_value_objs: list</span>
<span class="sd">                Instances of TimeValue</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">ts_int_index</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">endog</span><span class="p">))</span>
            <span class="n">time_value_objs</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="k">for</span> <span class="n">int_idx</span> <span class="ow">in</span> <span class="n">ts_int_index</span><span class="p">:</span>
                <span class="n">time_value_objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">TimeValue</span><span class="p">(</span><span class="n">index</span><span class="o">=</span><span class="n">int_idx</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">endog</span><span class="p">[</span><span class="n">int_idx</span><span class="p">]))</span>
            <span class="k">return</span> <span class="n">time_value_objs</span>

        <span class="k">def</span> <span class="nf">get_pmml_datatype_optype</span><span class="p">(</span><span class="n">series_obj</span><span class="p">):</span>
            <span class="n">pmml_data_type</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">pmml_op_type</span> <span class="o">=</span> <span class="s1">&#39;continuous&#39;</span>
            <span class="k">if</span> <span class="nb">str</span><span class="p">(</span><span class="n">series_obj</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;datetime64[ns]&#39;</span><span class="p">,</span> <span class="s1">&#39;datetime64[ns, tz]&#39;</span><span class="p">,</span> <span class="s1">&#39;timedelta[ns]&#39;</span><span class="p">]:</span>
                <span class="n">pmml_data_type</span> <span class="o">=</span> <span class="n">DATATYPE</span><span class="o">.</span><span class="n">DATETIME</span><span class="o">.</span><span class="n">value</span>
            <span class="k">elif</span> <span class="nb">str</span><span class="p">(</span><span class="n">series_obj</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;float32&#39;</span><span class="p">:</span>
                <span class="n">pmml_data_type</span> <span class="o">=</span> <span class="n">DATATYPE</span><span class="o">.</span><span class="n">FLOAT</span><span class="o">.</span><span class="n">value</span>
            <span class="k">elif</span> <span class="nb">str</span><span class="p">(</span><span class="n">series_obj</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;float64&#39;</span><span class="p">:</span>
                <span class="n">pmml_data_type</span> <span class="o">=</span> <span class="n">DATATYPE</span><span class="o">.</span><span class="n">DOUBLE</span><span class="o">.</span><span class="n">value</span>
            <span class="k">elif</span> <span class="nb">str</span><span class="p">(</span><span class="n">series_obj</span><span class="o">.</span><span class="n">dtype</span><span class="p">)</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;int64&#39;</span><span class="p">,</span> <span class="s1">&#39;int32&#39;</span><span class="p">]:</span>
                <span class="n">pmml_data_type</span> <span class="o">=</span> <span class="n">DATATYPE</span><span class="o">.</span><span class="n">INTEGER</span><span class="o">.</span><span class="n">value</span>
            
            <span class="k">return</span> <span class="n">pmml_data_type</span><span class="p">,</span> <span class="n">pmml_op_type</span>

        <span class="k">def</span> <span class="nf">get_data_field_objs</span><span class="p">():</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Create a list with instances of DataField</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">data_field_objs</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="n">index_name</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">name</span>
            <span class="n">idx_data_type</span><span class="p">,</span> <span class="n">idx_op_type</span> <span class="o">=</span> <span class="n">get_pmml_datatype_optype</span><span class="p">(</span><span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">_index</span><span class="p">)</span>
            <span class="n">data_field_objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">DataField</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">index_name</span><span class="p">,</span> <span class="n">dataType</span><span class="o">=</span><span class="n">idx_data_type</span><span class="p">,</span> <span class="n">optype</span><span class="o">=</span><span class="n">idx_op_type</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;DataFrame&#39;</span><span class="p">:</span>
                <span class="n">ts_name</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;Series&#39;</span><span class="p">:</span>
                <span class="n">ts_name</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="n">name</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">ts_name</span> <span class="o">=</span> <span class="s1">&#39;input&#39;</span>
            <span class="n">ts_data_type</span><span class="p">,</span> <span class="n">ts_op_type</span> <span class="o">=</span> <span class="n">get_pmml_datatype_optype</span><span class="p">(</span><span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">endog</span><span class="p">)</span>
            <span class="n">data_field_objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">DataField</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">ts_name</span><span class="p">,</span> <span class="n">dataType</span><span class="o">=</span><span class="n">ts_data_type</span><span class="p">,</span> <span class="n">optype</span><span class="o">=</span><span class="n">ts_op_type</span><span class="p">))</span>
            <span class="k">return</span> <span class="n">data_field_objs</span>

        <span class="k">def</span> <span class="nf">get_mining_field_objs</span><span class="p">():</span>
            <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            Create a list with instances of MiningField</span>
<span class="sd">            &quot;&quot;&quot;</span>
            <span class="n">mining_field_objs</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;DataFrame&#39;</span><span class="p">:</span>
                <span class="n">ts_name</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="n">columns</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="k">elif</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;Series&#39;</span><span class="p">:</span>
                <span class="n">ts_name</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="n">name</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">ts_name</span> <span class="o">=</span> <span class="s1">&#39;input&#39;</span>
            <span class="n">idx_name</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">orig_endog</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">name</span>
            <span class="n">idx_usage_type</span> <span class="o">=</span> <span class="n">FIELD_USAGE_TYPE</span><span class="o">.</span><span class="n">ORDER</span><span class="o">.</span><span class="n">value</span>
            <span class="n">mining_field_objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">MiningField</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">idx_name</span><span class="p">,</span> <span class="n">usageType</span><span class="o">=</span><span class="n">idx_usage_type</span><span class="p">))</span>
            <span class="n">ts_usage_type</span> <span class="o">=</span> <span class="n">FIELD_USAGE_TYPE</span><span class="o">.</span><span class="n">TARGET</span><span class="o">.</span><span class="n">value</span>
            <span class="n">mining_field_objs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">MiningField</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">ts_name</span><span class="p">,</span> <span class="n">usageType</span><span class="o">=</span><span class="n">ts_usage_type</span><span class="p">))</span>
            <span class="k">return</span> <span class="n">mining_field_objs</span>

        <span class="n">n_samples</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">nobs</span>
        <span class="n">n_columns</span> <span class="o">=</span> <span class="mi">1</span>  <span class="c1"># because we are dealing with Series object</span>
        <span class="n">function_name</span> <span class="o">=</span> <span class="n">MINING_FUNCTION</span><span class="o">.</span><span class="n">TIMESERIES</span><span class="o">.</span><span class="n">value</span>
        <span class="n">best_fit</span> <span class="o">=</span> <span class="n">TIMESERIES_ALGORITHM</span><span class="o">.</span><span class="n">EXPONENTIAL_SMOOTHING</span><span class="o">.</span><span class="n">value</span>
        <span class="n">extension_objs</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
        <span class="n">alpha</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;smoothing_level&#39;</span><span class="p">]</span>  <span class="c1"># alpha is smoothing parameter for level</span>
        <span class="n">level_smooth_val</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">level</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>  <span class="c1"># smoothed level at last time-index</span>
        <span class="n">initial_level</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;initial_level&#39;</span><span class="p">]</span>
        <span class="c1"># extension_objs.append(Extension(name=&#39;initialLevel&#39;, value=initial_level))</span>
        <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;smoothing_slope&#39;</span><span class="p">]):</span>
            <span class="n">gamma</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">gamma</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;smoothing_slope&#39;</span><span class="p">]</span>  <span class="c1"># gamma is smoothing parameter for trend</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;smoothing_seasonal&#39;</span><span class="p">]):</span>
            <span class="n">delta</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">delta</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;smoothing_seasonal&#39;</span><span class="p">]</span>  <span class="c1"># delta is smoothing parameter for seasonality</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;damping_slope&#39;</span><span class="p">]):</span>
            <span class="n">phi</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">phi</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;damping_slope&#39;</span><span class="p">]</span>  <span class="c1"># damping parameter; which is applied on trend/slope</span>
        <span class="k">if</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">trend</span><span class="p">:</span>  <span class="c1"># model_obj.trend can take values in {&#39;add&#39;, &#39;mul&#39;, None}</span>
            <span class="n">trend_smooth_val</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">slope</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">initial_trend</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;initial_slope&#39;</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">trend</span> <span class="o">==</span> <span class="s1">&#39;add&#39;</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">damped</span><span class="p">:</span>
                    <span class="n">trend_type</span> <span class="o">=</span> <span class="n">EXPONENTIAL_SMOOTHING_TREND</span><span class="o">.</span><span class="n">DAMPED_ADDITIVE</span><span class="o">.</span><span class="n">value</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">trend_type</span> <span class="o">=</span> <span class="n">EXPONENTIAL_SMOOTHING_TREND</span><span class="o">.</span><span class="n">ADDITIVE</span><span class="o">.</span><span class="n">value</span>
            <span class="k">else</span><span class="p">:</span>  <span class="c1"># model_obj.trend == &#39;mul&#39;:</span>
                <span class="k">if</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">damped</span><span class="p">:</span>
                    <span class="n">trend_type</span> <span class="o">=</span> <span class="n">EXPONENTIAL_SMOOTHING_TREND</span><span class="o">.</span><span class="n">DAMPED_MULTIPLICATIVE</span><span class="o">.</span><span class="n">value</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">trend_type</span> <span class="o">=</span> <span class="n">EXPONENTIAL_SMOOTHING_TREND</span><span class="o">.</span><span class="n">MULTIPLICATIVE</span><span class="o">.</span><span class="n">value</span>
            <span class="n">trend_obj</span> <span class="o">=</span> <span class="n">Trend_ExpoSmooth</span><span class="p">(</span><span class="n">trend</span><span class="o">=</span><span class="n">trend_type</span><span class="p">,</span> <span class="n">gamma</span><span class="o">=</span><span class="n">gamma</span><span class="p">,</span> <span class="n">phi</span><span class="o">=</span><span class="n">phi</span><span class="p">,</span> <span class="n">smoothedValue</span><span class="o">=</span><span class="n">trend_smooth_val</span><span class="p">)</span>
            <span class="c1"># extension_objs.append(Extension(name=&#39;initialTrend&#39;, value=initial_trend))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">trend_obj</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">seasonal</span><span class="p">:</span>  <span class="c1"># model_obj.seasonal can take values in {&#39;add&#39;, &#39;mul&#39;, None}</span>
            <span class="n">period</span> <span class="o">=</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">seasonal_periods</span>
            <span class="n">initial_seasons</span> <span class="o">=</span> <span class="n">ArrayType</span><span class="p">(</span><span class="n">n</span><span class="o">=</span><span class="n">period</span><span class="p">,</span> <span class="n">type_</span> <span class="o">=</span> <span class="n">ARRAY_TYPE</span><span class="o">.</span><span class="n">REAL</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
            <span class="n">content_value</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;initial_seasons&#39;</span><span class="p">]])</span>
            <span class="n">initial_seasons</span><span class="o">.</span><span class="n">content_</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">content_value</span>
            <span class="k">if</span> <span class="n">results_obj</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">seasonal</span> <span class="o">==</span> <span class="s1">&#39;add&#39;</span><span class="p">:</span>
                <span class="n">seasonal_type</span> <span class="o">=</span> <span class="n">EXPONENTIAL_SMOOTHING_SEASONALITY</span><span class="o">.</span><span class="n">ADDITIVE</span><span class="o">.</span><span class="n">value</span>
            <span class="k">else</span><span class="p">:</span>  <span class="c1"># model_obj.seasonal == &#39;mul&#39;:</span>
                <span class="n">seasonal_type</span> <span class="o">=</span> <span class="n">EXPONENTIAL_SMOOTHING_SEASONALITY</span><span class="o">.</span><span class="n">MULTIPLICATIVE</span><span class="o">.</span><span class="n">value</span>
            <span class="n">season_obj</span> <span class="o">=</span> <span class="n">Seasonality_ExpoSmooth</span><span class="p">(</span><span class="n">type_</span><span class="o">=</span><span class="n">seasonal_type</span><span class="p">,</span> <span class="n">period</span><span class="o">=</span><span class="n">period</span><span class="p">,</span> <span class="n">delta</span><span class="o">=</span><span class="n">delta</span><span class="p">,</span>
                                                <span class="n">Array</span><span class="o">=</span><span class="n">initial_seasons</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">season_obj</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">pmml</span> <span class="o">=</span> <span class="n">PMML</span><span class="p">(</span>
            <span class="n">version</span><span class="o">=</span><span class="s1">&#39;4.4&#39;</span><span class="p">,</span>
            <span class="n">Header</span><span class="o">=</span><span class="n">Header</span><span class="p">(</span>
                <span class="n">copyright</span><span class="o">=</span><span class="s2">&quot;Copyright (c) 2018 Software AG&quot;</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="n">description</span> <span class="k">if</span> <span class="n">description</span> <span class="k">else</span> <span class="s2">&quot;Exponential Smoothing Model&quot;</span><span class="p">,</span>
                <span class="n">Timestamp</span><span class="o">=</span><span class="n">Timestamp</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()),</span>
                <span class="n">Application</span><span class="o">=</span><span class="n">Application</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;Nyoka&quot;</span><span class="p">,</span><span class="n">version</span><span class="o">=</span><span class="n">metadata</span><span class="o">.</span><span class="n">__version__</span><span class="p">)</span>
            <span class="p">),</span>
            <span class="n">DataDictionary</span><span class="o">=</span><span class="n">DataDictionary</span><span class="p">(</span><span class="n">numberOfFields</span><span class="o">=</span><span class="n">n_columns</span><span class="p">,</span> <span class="n">DataField</span><span class="o">=</span><span class="n">get_data_field_objs</span><span class="p">()),</span>
            <span class="n">TimeSeriesModel</span><span class="o">=</span><span class="p">[</span><span class="n">TimeSeriesModel</span><span class="p">(</span>
                <span class="n">modelName</span><span class="o">=</span> <span class="n">model_name</span> <span class="k">if</span> <span class="n">model_name</span> <span class="k">else</span> <span class="s1">&#39;simple exponential smoothing&#39;</span><span class="p">,</span>
                <span class="n">functionName</span><span class="o">=</span><span class="n">function_name</span><span class="p">,</span> <span class="n">bestFit</span><span class="o">=</span><span class="n">best_fit</span><span class="p">,</span> <span class="n">isScorable</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                <span class="n">MiningSchema</span><span class="o">=</span><span class="n">MiningSchema</span><span class="p">(</span><span class="n">MiningField</span><span class="o">=</span><span class="n">get_mining_field_objs</span><span class="p">()),</span>
                <span class="n">TimeSeries</span><span class="o">=</span><span class="p">[</span><span class="n">TimeSeries</span><span class="p">(</span>
                    <span class="n">usage</span><span class="o">=</span><span class="n">TIMESERIES_USAGE</span><span class="o">.</span><span class="n">ORIGINAL</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="n">startTime</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">endTime</span><span class="o">=</span><span class="n">n_samples</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span> <span class="n">interpolationMethod</span><span class="o">=</span><span class="s1">&#39;none&#39;</span><span class="p">,</span>
                    <span class="n">TimeValue</span><span class="o">=</span><span class="n">get_time_value_objs</span><span class="p">()</span>
                <span class="p">)],</span>
                <span class="n">ExponentialSmoothing</span><span class="o">=</span><span class="n">ExponentialSmoothing</span><span class="p">(</span>
                    <span class="n">Level</span><span class="o">=</span><span class="n">Level</span><span class="p">(</span><span class="n">alpha</span><span class="o">=</span><span class="n">alpha</span><span class="p">,</span> <span class="n">smoothedValue</span><span class="o">=</span><span class="n">level_smooth_val</span><span class="p">),</span>
                    <span class="n">Trend_ExpoSmooth</span><span class="o">=</span><span class="n">trend_obj</span><span class="p">,</span>
                    <span class="n">Seasonality_ExpoSmooth</span><span class="o">=</span><span class="n">season_obj</span><span class="p">,</span>
                <span class="p">),</span>
                <span class="c1"># Extension=extension_objs</span>
            <span class="p">)]</span>
        <span class="p">)</span>
        <span class="n">pmml</span><span class="o">.</span><span class="n">export</span><span class="p">(</span><span class="n">outfile</span><span class="o">=</span><span class="nb">open</span><span class="p">(</span><span class="n">pmml_file_name</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">),</span> <span class="n">level</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, maintainer@nyoka.org

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>